/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package colordrips;


import java.util.Random;
import javax.swing.ImageIcon;
import javax.swing.JLabel;

/**
 *
 * @author SimaoItalo
 */
public class Block extends JLabel {
    
    private boolean empty;
    private String color;
    private Random random;
    private int iPosition;
    private int jPosition;

    public Block(int iPosition, int jPosition, boolean isborder) {
        this.iPosition = iPosition;
        this.jPosition = jPosition;
        if(!isborder){
          chooseColor();
          this.empty = false;
        } else {
            this.color = "border";
            this.empty = true;
        }
    }
    
    private void chooseColor(){
        random = new Random();
        int colorNumber = random.nextInt(4);
        switch(colorNumber){
            case 0:
                this.color = "blue";
                setIcon(new ImageIcon(getClass().getResource("/assets/circle_blue48.png")));
                break;
            case 1:
                this.color = "red";
                setIcon(new ImageIcon(getClass().getResource("/assets/circle_red48.png")));
                break;
            case 2:
                this.color = "green";
                setIcon(new ImageIcon(getClass().getResource("/assets/circle_green48.png")));
                break;
            case 3:
                this.color = "orange";
                setIcon(new ImageIcon(getClass().getResource("/assets/circle_orange48.png")));
                break;
        } 
                    
    }
    
    public String getColor(){
        return this.color;
    }

    public boolean isEmpty() {
        return empty;
    }

    public void setIsmarked(boolean empty) {
        this.empty = empty;
    }

    public int getiPosition() {
        return iPosition;
    }

    public int getjPosition() {
        return jPosition;
    }
    
    public boolean hasSameColor(Block selectedBlock){
        if (this.isEmpty()){
            return false;
        } else if(this.color.equalsIgnoreCase(selectedBlock.color)) {
            return true;
        } else {
            return false;
        }
    }
    
    public void clearBlock(){
        this.color = "none";
        this.empty = true;
    }
    
    public void setImage(String url){
        setIcon(new ImageIcon(getClass().getResource(url)));
    }
    
}
